1. Array Simulation. The output produced is as follows. Original List Final List -------------------------------------------------------------- [12, 7] [13, 8] [2, 3, 4, 5, 6] [3, 5, 5, 5, 6] [3, 4, 5, 7, 9] [3, 5, 7, 9, 10] [2, 3, 5, 7, 9] [3, 5, 7, 9, 10] [4, 5, 9, 6, 2] [5, 7, 11, 7, 2] 2. Inheritance. The output produced is as follows. b 1 b 1 d 1 c 1 b 2 b 2 d 2 d 2 d a d d 3. Many solutions possible, one is shown below: public static void adjustTV(Scanner tokenScan){ int volume = 0; boolean on = false; while(tokenScan.hasNext()){ String setting = tokenScan.next(); if(setting.equals("volume")){ int volumeChange = tokenScan.nextInt(); if(on){ volume += volumeChange; if(volume < 0){ volume = 0; } if(volume > 10){ volume = 10; } } } else { //"power" on = !on; } } if(on){ System.out.println("The TV is on"); }else{ System.out.println("The TV is off"); } System.out.println("The volume is " + volume); } 4. Many solutions possible, one is shown below: public static int numUnique(int[] list) { if (list.length == 0) { return 0; } else { int count = 1; for (int i = 1; i < list.length; i++) { if (list[i] != list[i - 1]) { count++; } } return count; } } 5. Several solutions possible, one is shown below: public class Chameleon extends Critter { private int count = 0; public Action getMove(CritterInfo info) { count++; if (count % 3 == 1) { return Action.INFECT; } else if (info.getFront() == Neighbor.EMPTY) { return Action.HOP; } else { return Action.RIGHT; } } public Color getColor() { if (count % 3 == 0) { return Color.RED; } else if (count % 3 == 1) { return Color.WHITE; } else { return Color.BLUE; } } public String toString() { if (count % 3 == 0) { return "R"; } else if (count % 3 == 1) { return "W"; } else { return "B"; } } } 7. Many solutions possible, some are shown below: public static int analyzeParagraphs(Scanner input) { int max = 0; while (input.hasNextLine()) { String line = input.nextLine(); int count = 0; while (!line.equals("
")) { count++; line = input.nextLine(); } System.out.println(count + "-line paragraph"); if (count > max) { max = count; } } return max; } public static int analyzeParagraphs(Scanner input) { int max = 0; int count = 0; while (input.hasNextLine()) { String line = input.nextLine(); if (line.equals("
")) {
System.out.println(count + "-line paragraph");
count = 0;
} else {
count++;
}
if (count > max) {
max = count;
}
}
return max;
}
8. Many solutions possible, some are shown below:
public static void removeAdjacentMatches(ArrayList